{include file='public/header' /}
    <style type="text/css">
        .header span{background: #009688;margin-left: 30px;padding: 10px;color:#ffffff;}
        .header div{border-bottom: solid 2px #009688;margin-top: 8px;}
        .header button{float: right;margin-top: -5px;}
    </style>
</head>
<body style="padding: 10px;">
<div class="header">
    <span>房源列表</span>
    <button class="layui-btn layui-btn-sm" onclick="editor()">添加</button>
    <div></div>

</div>
<from class="layui-form" action="">
    <div class="layui-form-item" style="padding-top: 15px">
        <div class="layui-inline">
            <div class="layui-input-inline layui-show-xs-block">
                <input type="text" name="con_house_cqdz" placeholder="请输入地址信息" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline layui-show-xs-block">
                <input type="text" name="con_house_jssl_s" placeholder="请输入居室" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline layui-show-xs-block">
                <input type="text" name="con_house_cqzslb" placeholder="请输入类型" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline layui-show-xs-block">
                <input type="text" name="con_house_cqzm" placeholder="请输入特色" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline layui-show-xs-block">
                <button class="layui-btn" id="select" lay-submit lay-filter="select"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </div>
    </div>
</from>
<table id="lists" lay-filter="lists"></table>


<script type="text/javascript">
    layui.use(['layer','form','table'],function(){
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        table.render({
            elem: '#lists'
            ,height: 'full-144'
            ,url: '__PUBLIC__/admin/apartment/check?msg=-1' //数据接口
            ,page: true //开启分页
            // ,size: 'sm'
            ,cellMinWidth:60
            // ,even: true
            ,cols: [[ //表头
                {field: 'tch_id', title: 'id', minWidth:120, sort: true}
                ,{field: 'con_house_province', title: '省', minWidth:120}
                ,{field: 'con_house_city', title: '市', minWidth:120, sort: true}
                ,{field: 'con_house_area', title: '区', minWidth:120, sort: true}
                ,{field: 'con_house_gyxxdz', title: '位置', minWidth:120}
                ,{field: 'con_house_jzmj', title: '面积', minWidth:120,}
                ,{field: 'create_time', title: '添加时间', minWidth:200, }
                //,{field: 'status', title: '风控状态', minWidth: 120, sort: true}
                ,{field: 'operation', title: '操作',minWidth:120,}
            ]]
        });
        form.on('switch', function(data){
            // console.log(data.elem.id); //得到checkbox原始DOM对象
            // console.log(data.elem.checked); //开关是否开启，true或者false
            // console.log(data.value); //开关value值，也可以通过data.elem.value得到
            // console.log(data.othis); //得到美化后的DOM对象
            layer.msg('正在提交请稍候。。。', {icon: 16,time: 100000,shade : [0.5 , '#000' , true]});
            $.post('__PUBLIC__/admin/apartment/status',{'id':data.elem.id,'status':data.elem.checked},function (res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                    if(data.elem.checked == false){
                        data.elem.checked = true
                    }else {
                        data.elem.checked = false
                    }
                    form.render();
                }else {
                    layer.msg(res.msg,{icon:1,time:1100});
                    //location.reload();
                }
            },'json');
        });
        form.on('submit', function(data){
            con_house_cqdz = data.field.con_house_cqdz;
            con_house_jssl_s = data.field.con_house_jssl_s;
            con_house_cqzslb = data.field.con_house_cqzslb;
            con_house_cqzm = data.field.con_house_cqzm;
            getdata = '';
            if (con_house_cqdz && typeof(con_house_cqdz)!=undefined && con_house_cqdz!=0) {
                getdata += '&con_house_cqdz=' + con_house_cqdz;
            }
            if (con_house_jssl_s && typeof(con_house_jssl_s)!=undefined && con_house_jssl_s!=0) {
                getdata += '&con_house_jssl_s=' + con_house_jssl_s;
            }
            if (con_house_cqzslb && typeof(con_house_cqzslb)!=undefined && con_house_cqzslb!=0) {
                getdata += '&con_house_cqzslb=' + con_house_cqzslb;
            }
            if (con_house_cqzm && typeof(con_house_cqzm)!=undefined && con_house_cqzm!=0) {
                getdata += '&con_house_cqzm=' + con_house_cqzm;
            }
            var table = layui.table;
            table.render({
                elem: '#lists'
                ,height: 'full-144'
                ,url: '__PUBLIC__/admin/apartment/check?msg=1'+getdata //数据接口
                ,page: true //开启分页
                // ,size: 'sm'
                ,cellMinWidth:60
                // ,even: true
                ,cols: [[ //表头
                    {field: 'tch_id', title: 'id', minWidth:120, sort: true}
                    ,{field: 'con_house_province', title: '省', minWidth:120}
                    ,{field: 'con_house_city', title: '市', minWidth:120, sort: true}
                    ,{field: 'con_house_area', title: '区', minWidth:120, sort: true}
                    ,{field: 'con_house_gyxxdz', title: '位置', minWidth:120}
                    ,{field: 'con_house_jzmj', title: '面积', minWidth:120}
                    ,{field: 'create_time', title: '添加时间', minWidth:200, }
                    //,{field: 'status', title: '风控状态', minWidth: 120, sort: true}
                    ,{field: 'operation', title: '操作'}
                ]]
            });
            return false;
        });
    });

    // 添加编辑
    function editor(id){
        layer.open({
            type: 2,
            title: id>0?'编辑管理员':'添加房源',
            shade: 0.3,
            area: ['1080px', '720px'],
            content: '__PUBLIC__/admin/apartment/room?id='+id
        });
    }
    // 删除业务员
    function del(id){
        var table = layui.table;
        var item_table = table.cache['lists'];
        console.log(item_table);
        for (var index in item_table) {
            if(item_table[index].tch_id == id){
                var name = item_table[index].tch_id;
            }
        }
        layer.confirm('确认要删除'+name+'号房子吗？',{
            btn: ['是的','取消'] //按钮
        }, function(){
            var $ = layui.jquery;
            $.post('__PUBLIC__/admin/apartment/del',{'id':id},function (res){
                if(res.code>0){
                    layer.alert(res.msg,{icon:2});
                }else {
                    layer.msg(res.msg,{icon:1,time:1100});
                    location.reload();
                }
            },'json');
        });
    }
</script>
</body>
</html>
